import PlatformUtil from "../Platforms/PlatformUtil";
export default class XmlToolController {

    public static readonly instance = new XmlToolController();

    private constructor() { }

    serverPath: string = "https://api.taoqi001.com";//声明网络方法

    public httpUtils(url: string, dataDic: object, _cbSuccess: Function, _cbFail: Function,_cbError: Function) {//声明公共方法

        var sendData = PlatformUtil.platform.params;

        let fullData = {}

        fullData = Object.assign({}, sendData, dataDic)

        var xhr = new XMLHttpRequest();

        xhr.timeout = 3000;

        xhr.open('POST', this.serverPath + url, true);

        xhr.onreadystatechange = function (e) {

            if (xhr.readyState == 4 && xhr.status == 200) {

                if (JSON.parse(xhr.responseText).errcode == 0) {

                    typeof _cbSuccess == "function" && _cbSuccess(JSON.parse(xhr.responseText).data);
 

                } else {

                    typeof _cbFail == "function" && _cbFail(JSON.parse(xhr.responseText));//如果是个函数执行后面

                }

            }

        };
        xhr.ontimeout = function (e) { };
        xhr.onerror = function (e) {
            console.log("网络请求错误",e)
            typeof _cbError == "function" && _cbError(e);//如果是个函数执行后面
            // isHttpError=true
        };
        xhr.onprogress = function (e) {
            // console.log("加载进度")
        }
        xhr.send(JSON.stringify(fullData));
           console.log("网络请求字典",fullData)

    }

}